package com.qingke.easyjava.springweb.servlet;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.qingke.easyjava.springweb.service.GreetingService;

public class HelloServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      
		  WebApplicationContext wac=WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
		  
		  GreetingService service =wac.getBean(GreetingService.class);
		  
		  
		  OutputStream os =response.getOutputStream();
		  os.write(service.greeting().getBytes());
		  os.flush();
		  os.close();
		  
	}


}
